<template>
  <header class="header">
    <h1>todos</h1>
    <input id="toggle-all" class="toggle-all" type="checkbox" v-model="all" />
    <label for="toggle-all"></label>
    <input
      class="new-todo"
      placeholder="输入任务名称-回车确认"
      autofocus
      @keydown.enter="add"
      v-model="content"
    />
  </header>
</template>

<script>
export default {
  props: {
    list: {
      type: Array,
      required: true,
    },
  },

  data() {
    return {
      content: "",
    };
  },

  methods: {
    add() {
      this.$emit("addItem", this.content);
      this.content = "";
    },
  },
  computed: {
    all: {
      get() {
        return this.list.length > 0 && this.list.every((item) => item.isDone);
      },
      set(val) {
        this.list.forEach((item) => (item.isDone = val));
      },
    },
  },
};
</script>
